<?
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'mod_pbny_weekly_leaders_helper.php' );
require_once( dirname(__FILE__).DS.'phpFlickr.php' );

$models = array('season', 'playergamestat', 'player', 'pic', 'team', 'person', 'schedule', 
				'video', 'seasondivision', 'divisionconference', 'division', 'conference',
				'conferenceteam');
foreach($models as $model)
	require_once(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_pbny' . DS . 'models' . DS . "$model.php");

// variables needed for the site
$mseason   = JModel::getInstance( 'season', 'seasonmodel' );
$season    = $mseason->get_latest();

if($season){
	$week     = ModPbnyWeeklyLeadersHelper::getWeek(time(), $season);
	
	$divisions= ModPbnyWeeklyLeadersHelper::getDivisions($season);
	
	foreach($divisions as $division){
		
		$conferences    = ModPbnyWeeklyLeadersHelper::getConferences($division);
		
		$schedules      = ModPbnyWeeklyLeadersHelper::getSchedules($conferences, $week->start_date, $week->end_date);
		
		$stats		    = ModPbnyWeeklyLeadersHelper::getStats($schedules);
		
		$teams[$division->id]    = ModPbnyWeeklyLeadersHelper::getTeams($conferences);
		
		$points[$division->id]   = ModPbnyWeeklyLeadersHelper::getTopPoints($stats);
		
		$rebounds[$division->id] = ModPbnyWeeklyLeadersHelper::getTopRebounds($stats);
		
		$assists[$division->id]  = ModPbnyWeeklyLeadersHelper::getTopAssists($stats);
		
		$steals[$division->id]   = ModPbnyWeeklyLeadersHelper::getTopSteals($stats);
		
		$blocks[$division->id]   = ModPbnyWeeklyLeadersHelper::getTopBlocks($stats);
	
	    $players[$division->id]  = ModPbnyWeeklyLeadersHelper::getPlayerDetails($points[$division->id],
		                                                                        $rebounds[$division->id],
																				$assists[$division->id],
																				$steals[$division->id],
																				$blocks[$division->id]);
	}

}
require( JModuleHelper::getLayoutPath( 'mod_pbny_weekly_leaders' ) );
?>